<template>
	<view class="box">
		<view class="nav">
			<u-navbar :is-back="false" title="我的"></u-navbar>
		</view>
		<view class="container_br userInfo">
			<view class="avatar_box flc">
				<view class="avatar">
					<u-avatar :src="userInfo.avatar_format" mode="circle" size="140" ></u-avatar>
				</view>
				<view class="name" v-if="userInfo">
					<span>{{userInfo.nickname}}</span>
				</view>
				<view class="name" v-else @click="goLogin">
					<span>立即登录</span>
				</view>
			</view>
			<view class="balance_box jsbc">
				<view class="balance" @click="goPoint">
					<view class="num">
						{{userInfo.balance||0}}
					</view>
					<view class="point" >
						积分
					</view>
				</view>
				<view class="team" v-if="userInfo.level_id==3||userInfo.level_id==2" @click="goPages">
					团队
				</view>
			</view>
		</view>
		<view class="container_br order">
			<view class="order_top jsbc">
				<view class="left flc">
					<u-icon :name="'/static/icon/qbdd.png'" size="26"></u-icon> <span class="ml2">全部订单</span>
				</view>
				<view class="right flc" @click="goOrder(-1)">
					 <span class="mr2">更多</span><u-icon name="arrow-right'" size="32" color="#dedede"></u-icon>
				</view>
			</view>
			<view class="ordertab jsbc">
				<view class="item" v-for="(item,index) in sendOrder" :key="index" @click="goOrder(index)">
					<view class="icon">
						<u-icon :name="item.icon" size="60"></u-icon>
					</view>
					<view class="name">
						{{item.name}}
					</view>
					<u-badge type="error" :count="item.count" :offset='[-10,-10]' ></u-badge>
				</view>
			</view>
		</view>
		<view class="container_br tabs">
				<view class="left flc">
					<u-icon :name="'/static/icon/grgl.png'" size="26"></u-icon> <span class="ml2">个人管理</span>
				</view>
			<view class="tabBox">
				<view class="item" v-for="(item,index) in tab" :key="index" @click="goPage(item)">
					<view class="icons">
						<u-icon :name="item.icon" size="60"></u-icon>
					</view>
					<view class="name">
						{{item.name}}
					</view>
				</view>
				<button open-type="contact" class="contactBox typeBtn">
					<view class="items">
						<view class="icons">
							<u-icon :name="'/static/icon/lxkf.png'" size="60"></u-icon>
						</view>
						<view class="name">
							联系客服
						</view>
					</view>
				</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getUserInfo,

	} from '../../api/user.js'
	import baseUrl from '@/config/config.js'
	import {closeload, tiao, toast, toastload} from '@/utils/common.js'
	export default {
		data() {
			return {
				style: {
					background: 'transparent'
				},
				userInfo:"",
				sendOrder: [
					{
						icon: "/static/icon/dfk.png",
						name: "待付款",
						count:""
					},
					{
						icon: "/static/icon/dfh.png",
						name: "待发货",
						count:""
					},
					{
						icon: "/static/icon/dsh.png",
						name: "待收货",
						count:""
					},
					{
						icon: "/static/icon/dpj.png",
						name: "已完成",
						count:""
					},
					{
						icon: "/static/icon/thh.png",
						name: "待退货",
						count:""
					}
				],
				
				tab: [{
						id: "0",
						name: "分享好友",
						icon: "/static/icon/fxhy.png",
						path: "/other/VIPCenter/VIPCenter?type=",
						type:""
					},
					{
						id: "1",
						name: "我的收藏",
						icon: "/static/icon/wdsc.png",
						path: "/page/userCollect/userCollect"
					},
					{
						id: "2",
						name: "我的足迹",
						icon: "/static/icon/wdzj.png",
						path: "/page/userCoupons/userCoupons"
					},
					
					{
						id: "3",
						name: "收货地址",
						icon: "/static/icon/shdz.png",
						path: "/other/delivery-address/delivery-address"
					},
					{
						id: "4",
						name: "意见反馈",
						icon: "/static/icon/yjfk.png",
						path: "/page/feedBack/feedBack"
					},
					{
						id: "5",
						name: "余额明细",
						icon: "/static/icon/yemx.png",
						path: "/page/bills/bills"
					},
					
					
					{
						id: "6",
						name: "积分明细",
						icon: "/static/icon/jfmx.png",
						path: "/page/pointBills/pointBills"
					},
					{
						id: "7",
						name: "个人设置",
						icon: "/static/icon/grsz.png",
						path: "/other/setting/setting"
					},
					{
						id: "8",
						name: "招募推广人",
						icon: "/static/icon/sqqd.png",
						path: "/other/partner/partner"
					},
					{
						id: "9",
						name: "我的预约",
						icon: "/static/icon/wdyy.png",
						path: "/page/orderManage/orderManage"
					},
					{
						id: "10",
						name: "积分商城",
						icon: "/static/icon/jfsc.png",
						path: "/page/pointShop/pointShop"
					},
					{
						id: "11",
						name: "我的兑换",
						icon: "/static/icon/wddh.png",
						path: "/other/myRedemptions/myRedemptions"
					}
					
				]
			}
		},
		onLoad(res) {
			console.log("邀请码",res);
			if (res.scene) {
				let str = res.scene
				let index = str.indexOf("3A")
				if (index != -1) {
					let hhh = str.substring(index + 2)
					console.log("hhh", hhh);
					uni.setStorageSync("sales_uid", hhh)
				}
			}
		},
		onShow() {
			let token = uni.getStorageSync("access_token")
			if (!token) {
				uni.showModal({
					title: '提示',
					content: "你还没有登录,是否去登录",
					cancelText: '取消',
					confirmText: '确定',
					success: function(res) {
						console.log(res);
						if (res.confirm == true) {
							uni.navigateTo({
								url: '/pages/wx-login/wx-login'
							})
						}

					},

				})
			} else {
				toastload()
				getUserInfo().then(res => {
					console.log("用户信息", res);
					if(res.error){
						closeload()
						uni.showModal({
							title: '提示',
							content: "你还没有登录,是否去登录",
							cancelText: '取消',
							confirmText: '确定',
							success: function(res) {
								console.log(res);
								if (res.confirm == true) {
									uni.navigateTo({
										url: '/pages/wx-login/wx-login'
									})
								}
						
							},
						
						})
					}else{
						closeload()
						this.userInfo = res.data.user
						console.log(res.data.user.level_id);
						if(res.data.user.level_id==3){
							this.tab[0].type=1
							uni.setStorageSync('code',res.data.user.code)
						}
						if(res.data.user.level_id==2){
								this.tab[0].type=2
						}
						if(res.data.user.level_id==1){
								this.tab[0].type=-1
						}
						if(res.data.user.level_id==0){
								this.tab[0].type=-1
						}
						if(res.data.order){
							for (let s in res.data.order) {
								this.sendOrder[s].count = res.data.order[s]
							}
						}
						
						console.log(this.sendOrder);
					}
				})
			}
		},
		methods: {
			goPage(item) {
				console.log(item);
				if(item.type){
					if(item.type==-1){
						toast("您没有权限,请申请成为推销员")
						return
					}
					tiao(item.path+item.type)
				}else{
					tiao(item.path)
				}
			},
			goOrder(index){
				index = index+1
				tiao('/page/myOrder/myOrder?id='+index)
			},
			goPages(){
				tiao('/other/uteam/uteam')
			},
			goPoint(){
				tiao('/page/pointBills/pointBills')
			},
			goLogin(){
				uni.navigateTo({
					url: '/pages/wx-login/wx-login'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.ubg {
		position: absolute;
		top: 0;
		width: 750rpx;
	}
	.typeBtn {
		width: 20%;
		background-color: rgba(0, 0, 0, 0);
		font-size: 26rpx;
		padding: 0;
		color: #333;
		margin: 0;
		height: 120rpx;
		color: #333;
		font-size: 26rpx;
		margin-top: 40rpx;
	
		&::after {
			border: none;
		}
	
		.items {
			width: 100%;
			height: 100%;
			display: flex;
			flex-direction: column;
			justify-content: space-evenly;
			align-items: center;
		}
	
		.items .icons {
			width: 60rpx;
			height: 60rpx;
			margin-top: 10rpx;
		}
	}
	.userInfo{
		min-height: 350rpx;
		background: url(https://vkceyugu.cdn.bspapp.com/VKCEYUGU-35ab61e2-32f4-47fa-aee5-ee9b5616a493/a51ae2d4-3a22-47cf-a352-02d8c54037b1.jpg) no-repeat;
		background-size: 100%;
		.name{
			margin-left: 20rpx;
			font-size: 32rpx;
			font-weight: 600rpx;
		}
		.balance_box{
			box-sizing: border-box;
			padding: 10rpx 80rpx;
			font-size: 32rpx;
			font-weight: 600;
			.point{
				display: flex;
				flex-direction: column;
				align-items: center;
			}
		}
	}
	.order{
		min-height: 240rpx;
		.ordertab{
			margin-top: 20rpx;
			.item{
				position: relative;
				display: flex;
				flex-direction: column;
				align-items: center;
				height: 100rpx;
				justify-content: space-between;
				font-size: 32rpx;
				font-weight: 600;
			}
		}
	}

.tabBox{
	display: flex;
	flex-wrap: wrap;
	align-items: center;
}
	.tabs .item {
		width: 20%;
		display: flex;
		flex-direction: column;
		justify-content: space-evenly;
		align-items: center;
		height: 120rpx;
		font-size: 26rpx;
		color: #333;
		margin-top: 40rpx;
	}
	.myOrder .item,
	.menubar .item{
		display: flex;
		flex-direction: column;
		align-items: center;
		height: 120rpx;
		justify-content: space-between;
		box-sizing: border-box;
		
	}
</style>